/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ucuenca.ec.nosql.modelos;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author mivkys
 */
public class Producto  implements Serializable{///MOGNO DB

    private int Id;
    private String ASIN = "";
    private String title = "";
    private String group = "";
    private int salesrank = 0;
    private List<String> similars;/////podria se neo4j
    private List<Category> categories;
    private List<Review> reviews;

    private int downloaded = 0;

    public Producto() {
        similars = new ArrayList<>();
        categories = new ArrayList<>();
        reviews = new ArrayList<>();
    }

    public Producto(int Id) {
        this.Id = Id;
        similars = new ArrayList<>();
        categories = new ArrayList<>();
        reviews = new ArrayList<>();
    }


    public Producto(int Id, String ASIN, String title, String group, int salesrank) {
        this.Id = Id;
        this.ASIN = ASIN;
        this.title = title;
        this.group = group;
        this.salesrank = salesrank;
        
        similars = new ArrayList<>();
        categories = new ArrayList<>();
        reviews = new ArrayList<>();
    }

    /**
     * @return the Id
     */
    public int getId() {
        return Id;
    }

    /**
     * @param Id the Id to set
     */
    public void setId(int Id) {
        this.Id = Id;
    }

    /**
     * @return the ASIN
     */
    public String getASIN() {
        return ASIN;
    }

    /**
     * @param ASIN the ASIN to set
     */
    public void setASIN(String ASIN) {
        this.ASIN = ASIN;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the group
     */
    public String getGroup() {
        return group;
    }

    /**
     * @param group the group to set
     */
    public void setGroup(String group) {
        this.group = group;
    }

    /**
     * @return the salesrank
     */
    public int getSalesrank() {
        return salesrank;
    }

    /**
     * @param salesrank the salesrank to set
     */
    public void setSalesrank(int salesrank) {
        this.salesrank = salesrank;
    }

    /**
     * @return the similars
     */
    public List<String> getSimilars() {
        return similars;
    }

    /**
     * @param similars the similars to set
     */
    public void setSimilars(List<String> similars) {
        this.similars = similars;
    }
    
    /**
     * @return the categories
     */
    public List<Category> getCategories() {
        return categories;
    }

    /**
     * @param categories the categories to set
     */
    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    /**
     * @return the reviews
     */
    public List<Review> getReviews() {
        return reviews;
    }

    /**
     * @param reviews the reviews to set
     */
    public void setReviews(List<Review> reviews) {
        this.reviews = reviews;
    }

    /**
     * @return the downloaded
     */
    public int getDownloaded() {
        return downloaded;
    }

    /**
     * @param downloaded the downloaded to set
     */
    public void setDownloaded(int downloaded) {
        this.downloaded = downloaded;
    }

    /**
     * @return the avg_rating
     */
    public double getAvg_rating() {
        double avg_rating = 0.0;
        if(reviews==null)
            return 0;
        if(reviews.isEmpty())
            return 0;
        else{
            for (Review review : reviews) {
                avg_rating+=review.getRating();
            }
            
            return avg_rating/reviews.size();
        }
    }

    /**
     * @param avg_rating the avg_rating to set
     */
    public void setAvg_rating(double avg_rating) {
        //
    }

    /**
     * @return the total_reviews
     */
    public int getTotal_reviews() {
        return (reviews!=null)?reviews.size():0;
    }

    /**
     * @param total_reviews the total_reviews to set
     */
    public void setTotal_reviews(int total_reviews) {
        ///
    }

    /**
     * @return the total_categories
     */
    public int getTotal_categories() {
        return (categories!=null)?categories.size():0;
    }

    /**
     * @param total_categories the total_categories to set
     */
    public void setTotal_categories(int total_categories) {
        //
    }

    /**
     * @return the total_similars
     */
    public int getTotal_similars() {
        return (similars!=null)?similars.size():0;
    }

    /**
     * @param total_similars the total_similars to set
     */
    public void setTotal_similars(int total_similars) {
       //
    }
    public Set<String> subCategoriasSet(){
        Set<String> alphaSet = new HashSet<>();
        for (Category categorie : categories) {
            alphaSet.addAll(categorie.subCategoriasSet());
        }
        return alphaSet;
    }
    public boolean productoRecomendado(int customer){
    for (Review review : reviews) {
        if(review.getCustomer()==customer)
            return true;
    }
    return false;
}
}
